package cn.lg.soar.database.translate.mapper;

import cn.lg.soar.common.data.dict.DictItem;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 翻译查询数据库的 dao
 * @author luguoxiang
 * @date 2022/2/13
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
public interface TranslateMapper extends BaseMapper<DictItem> {

    /**
     * 获取单个对象
     * @param tableName
     * @param valueName
     * @param labelName
     * @param value
     * @return
     */
    @Select("SELECT ${labelName} as `label` FROM ${tableName} WHERE ${valueName}=#{value}")
    String text(
            @Param("tableName") String tableName,
            @Param("valueName") String valueName,
            @Param("labelName") String labelName,
            @Param("value") Object value
    );

    /**
     * 获取多个
     * @param tableName
     * @param valueName
     * @param labelName
     * @param values
     * @return
     */
    @Select("SELECT ${valueName} as `value`, ${labelName} as `label` FROM ${tableName}")
    IPage<DictItem<String>> page(
            IPage<DictItem<String>> page,
            @Param("tableName") String tableName,
            @Param("valueName") String valueName,
            @Param("labelName") String labelName
    );

}
